package cn.peach.order.controller;

import cn.peach.basic.exception.MyException;
import cn.peach.basic.util.AjaxResult;
import cn.peach.order.dto.SaveOrderDto;
import cn.peach.order.service.IOrderPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 提交订单的订单接口
 */
@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private IOrderPetService orderPetService;

    @PostMapping("/save")
    public AjaxResult placeOrder(@RequestBody SaveOrderDto dto) {
        try {
            orderPetService.placeOrder(dto);
            return AjaxResult.me();
        } catch (MyException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("提交失败");
        }
    }
}
